<template>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
        <van-list
            v-model="loading"
            :finished="finished"
            finished-text="数据见底了"
            @load="onLoad"
            :immediate-check="false"
        >
            <slot></slot>
        </van-list>
    </van-pull-refresh>
</template>


<script>
export default {
    data(){
        return {
            isLoading:false,
            loading:false,   // 判断上拉加载更多是否完成  
            finished:false,  // 数据见底了 
        }
    },
    props:['refreshData','listAdd'],
    methods:{
        onRefresh(){
            console.log("开始刷新")
            // this.isLoading = true 
            setTimeout(()=>{
                this.refreshData(()=>{
                    this.$toast("刷新成功")
                    this.isLoading = false
                })
            },200)
        },
        onLoad(){
            setTimeout(()=>{
                this.listAdd(()=>{
                     this.loading = false
                     this.$toast("加载更多成功")
                    console.log("loadmore - 上拉加载更多 ")
                },()=>{
                    this.finished = true;
                    this.$toast("数据见底了")
                })
               
            },0)
        }
    }
}
</script>
